/*i0/DZTnkyLJbxtpRv5YHeEjlgIAayf7nNKe50skxlHJRBFugw4+AF+leK+r2aMupmfI9AklmWTqf
JWM/nPz4ag==*/

import { ajax,metaCache } from 'nc-lightapp-front';
/**
 * 编辑单据时，动态控制往来对象的编辑性，不再通过编辑前事件控制
 * @param {*} props 
 * @param {*} formId 
 * @param {*} tableId 
 */
function objtypeEditable(props, formId, tableId) {
    var billtype = props.form.getFormItemsValue(formId, 'pk_billtype') ? props.form.getFormItemsValue(formId, 'pk_billtype').value : null;
    //往来对象 0=客户，1=供应商，2=部门，3=业务员
    var objtype = props.form.getFormItemsValue(formId, 'objtype') ? props.form.getFormItemsValue(formId, 'objtype').value : null;
    var isrefund = props.form.getFormItemsValue(formId, 'isrefund') ? props.form.getFormItemsValue(formId, 'isrefund').value : null;
    // if (billtype && (billtype == 'F1' || billtype == "23E1")) {
    //     //应付单、付款单往来对象是客户，控制往来对象、币种不可编辑
    //     if (objtype && objtype == "0") {
    //         props.form.setFormItemsDisabled(formId, { 'objtype': true });
    //         props.form.setFormItemsDisabled(formId, { 'pk_currtype': true });
    //         props.cardTable.setColEditableByKey(tableId, ['objtype', 'pk_currtype'], true)
    //     }
    // } else if (billtype && (billtype == 'F0' || billtype == 'F2' || billtype == "23E0")) {
    //     //应收单、收款单往来对象是供应商，控制往来对象、币种不可编辑
    //     if (objtype && objtype == "0") {
    //         props.form.setFormItemsDisabled(formId, { 'objtype': true });
    //         props.form.setFormItemsDisabled(formId, { 'pk_currtype': true });
    //         props.cardTable.setColEditableByKey(tableId, ['objtype', 'pk_currtype'], true)
    //     }
    // } else if ((billtype == 'F1' && isrefund) || (billtype == 'F3' && isrefund)) {
    //     //应付退款单、付款退款单控制客户和往来对象不可编辑
    //     props.form.setFormItemsDisabled(formId, { 'objtype': true, 'customer': true });
    //     props.cardTable.setColEditableByKey(tableId, ['objtype', 'customer'], true)
    // }
    if ((billtype == 'F1' && isrefund) || (billtype == 'F3' && isrefund)) {
        //应付退款单、付款退款单控制客户和往来对象不可编辑
        props.form.setFormItemsDisabled(formId, { 'objtype': true, 'customer': true });
        props.cardTable.setColEditableByKey(tableId, ['objtype', 'customer'], true)
    }
}

/**
 * 编辑单据时，动态控制承付、关联结算信息相关字段的编辑性
 * @param {*} props 
 * @param {*} formId 
 * @param {*} tableId 
 */
function dealCommisionPayField(props, formId, tableId) {
    //是否承付
    var isforce = props.form.getFormItemsValue(formId, 'isforce') ? props.form.getFormItemsValue(formId, 'isforce').value : false;
    var billtype = props.form.getFormItemsValue(formId, 'pk_billtype') ? props.form.getFormItemsValue(formId, 'pk_billtype').value : null;
    let supplier = props.form.getFormItemsValue(formId, 'supplier') ? props.form.getFormItemsValue(formId, 'supplier').value : null
    let customer = props.form.getFormItemsValue(formId, 'customer') ? props.form.getFormItemsValue(formId, 'customer').value : null
    if (billtype != 'F2' && billtype != 'F3') {
        return
    }
    //关联结算信息
    let src = props.getUrlParam('src') == 'settlement';
    if (isforce || src) {
        props.form.setFormItemsDisabled(formId, {
            pk_org: true,
            pk_org_v: true,
            objtype: true,
            supplier: true,
            customer: true,
            supplier_v: true,
            customer_v: true,
            pk_currtype: true,
            rate: true,
            payaccount: true,
            recaccount: true,
            money: true,
            local_money: true,
            grouplocal: true,
            grouprate: true,
            globallocal: true,
            globalrate: true,
            commpaybegindate: true,
            commpayenddate: true,
            isforce: true
        });
        props.cardTable.setColEditableByKey(
            tableId,
            [
                'objtype',
                'supplier',
                'customer',
                'supplier_v',
                'customer_v',
                'pk_currtype',
                'rate',
                'grouprate',
                'globalrate',
                'payaccount',
                'recaccount',
                'commpayer',
                'commpaystatus',
                'commpaytype',
                'money_de',
                'local_money_de',
                'quantity_de',
                'money_bal',
                'local_money_bal',
                'quantity_bal',
                'local_tax_de',
                'notax_de',
                'local_notax_de',
                'groupdebit',
                'grouptax_de',
                'groupnotax_de',
                'globaldebit',
                'globaltax_de',
                'globalnotax_de',
                'quantity_cr',
                'local_money_cr',
                'money_cr',
                'local_tax_cr',
                'notax_cr',
                'local_notax_cr',
                'groupcrebit',
                'grouptax_cre',
                'groupnotax_cre',
                'globalcrebit',
                'globaltax_cre',
                'globalnotax_cre',
                'occupationmny',
                'price',
                'groupbalance',
                'globalbalance',
                'taxprice',
                'caltaxmny',
                'nosubtax'
            ],
            true

        );
    }
    if (!supplier && billtype == 'F3') {
        props.form.setFormItemsDisabled(formId, { supplier: false });
        props.cardTable.setColEditableByKey(tableId, ['supplier'], false);
        props.form.setFormItemsDisabled(formId, { supplier_v: false });
        props.cardTable.setColEditableByKey(tableId, ['supplier_v'], false);
    }
    if (!customer && billtype == 'F2') {
        props.form.setFormItemsDisabled(formId, { "customer": false })
        props.cardTable.setColEditableByKey(tableId, ["customer"], false)
        props.form.setFormItemsDisabled(formId, { "customer_v": false })
        props.cardTable.setColEditableByKey(tableId, ["customer_v"], false)
    }
    if (billtype == 'F3') {
        props.cardTable.setColEditableByKey(tableId, ['isrefused', 'refuse_reason'], true);//付款单拒付不能编辑
    }
}
/**
 * 编辑单据时，动态控制承付、关联结算信息相关字段的编辑性（逆向）因为平台未处理表格，
 * initMetaByPkorg  和  resMetaAfterPkorgEdit 表单取得缓存 所以不需要处理表单，此处指还原dealCommisionPayField 中的表格编辑性
 * @param {*} props 
 * @param {*} formId 
 * @param {*} tableId 
 */
function dealCommisionPayFieldBack(props, formId, tableId) {
    //是否承付
    var isforce = props.form.getFormItemsValue(formId, 'isforce') ? props.form.getFormItemsValue(formId, 'isforce').value : false;
    var billtype = props.form.getFormItemsValue(formId, 'pk_billtype') ? props.form.getFormItemsValue(formId, 'pk_billtype').value : null;
    let supplier = props.form.getFormItemsValue(formId, 'supplier') ? props.form.getFormItemsValue(formId, 'supplier').value : null
    let customer = props.form.getFormItemsValue(formId, 'customer') ? props.form.getFormItemsValue(formId, 'customer').value : null
    if (billtype != 'F2' && billtype != 'F3') {
        return
    }
    //关联结算信息
    let src = props.getUrlParam('src') == 'settlement';
    if (isforce || src) {
        
        props.cardTable.setColEditableByKey(
            tableId,
            [
                'objtype',
                'supplier',
                'customer',
                'supplier_v',
                'customer_v',
                'pk_currtype',
                'rate',
                'grouprate',
                'globalrate',
                'payaccount',
                'recaccount',
                'commpayer',
                'commpaystatus',
                'commpaytype',
                'money_de',
                'local_money_de',
                'quantity_de',
                'money_bal',
                'local_money_bal',
                'quantity_bal',
                'local_tax_de',
                'notax_de',
                'local_notax_de',
                'groupdebit',
                'grouptax_de',
                'groupnotax_de',
                'globaldebit',
                'globaltax_de',
                'globalnotax_de',
                'quantity_cr',
                'local_money_cr',
                'money_cr',
                'local_tax_cr',
                'notax_cr',
                'local_notax_cr',
                'groupcrebit',
                'grouptax_cre',
                'groupnotax_cre',
                'globalcrebit',
                'globaltax_cre',
                'globalnotax_cre',
                'occupationmny',
                'price',
                'groupbalance',
                'globalbalance',
                'taxprice',
                'caltaxmny',
                'nosubtax'
            ],
            false

        );
    }
    if (!supplier && billtype == 'F3') {
       
        props.cardTable.setColEditableByKey(tableId, ['supplier'], true);
        props.cardTable.setColEditableByKey(tableId, ['supplier_v'], true);
    }
    if (!customer && billtype == 'F2') {
        props.cardTable.setColEditableByKey(tableId, ["customer"], true)
        props.cardTable.setColEditableByKey(tableId, ["customer_v"], true)
    }
    if (billtype == 'F3') {
        props.cardTable.setColEditableByKey(tableId, ['isrefused', 'refuse_reason'], false);//付款单拒付不能编辑
    }
}

/**
 * 付款单拉红字应收特殊字段编辑性
 * @param {*} props 
 * @param {*} formId 
 * @param {*} tableId 
 */
function F0ToF3FieldsEditable(props, formId, tableId) {
    props.form.setFormItemsDisabled(formId, { objtype: true, pk_currtype: true });
    props.cardTable.setColEditableByKey(tableId, ['objtype', 'pk_currtype'], true)
}

/**
 * 付款单拉付款申请特殊字段编辑性
 * @param {*} props 
 * @param {*} formId 
 * @param {*} tableId 
 */
function applyToF3FieldsEditable(props, formId, tableId) {
    props.form.setFormItemsDisabled(formId, { pk_org: true, pk_org_v: true, pk_currtype: true, billdate: true, supplier: true });
    props.cardTable.setColEditableByKey(tableId,
        ['pk_currtype', 'billdate', 'supplier', 'supplier_v', 'prepay', 'purchaseorder', 'invoiceno', 'contractno', 'quantity_de', 'pu_org', 'pu_deptid', 'pu_psndoc'],
        true)
    //付款银行账户如果不为空，则不可编辑
    var payaccount = props.form.getFormItemsValue(formId, 'payaccount') ? props.form.getFormItemsValue(formId, 'payaccount').value : null;
    if (payaccount) {
        props.form.setFormItemsDisabled(formId, { payaccount: true });
        props.cardTable.setColEditableByKey(tableId, ['payaccount'], true)
    }
}

/**
 * 收付款合同推应收应付字段编辑性控制
 * @param {*} props 
 * @param {*} formId 
 * @param {*} tableId 
 */
function fctToArapFieldEditable(props, formId, tableId) {
    let srcbilltype = props.getUrlParam('srcbilltype')
    if (srcbilltype && (srcbilltype == 'FCT1' || srcbilltype == 'FCT2')) {
        props.form.setFormItemsDisabled(formId, { pk_org: true, pk_org_v: true });
    }
}
/**
 * 采购订单付款计划的付款单，财务组织不可编辑(供应商不可编辑)
 * @param {*} props 
 * @param {*} formId 
 * @param {*} tableId 
 */
function puToArapFieldEditable(props, formId, tableId) {
    let srcbilltype = props.getUrlParam('srcbilltype')
    if (srcbilltype == '21') {
        props.form.setFormItemsDisabled(formId, { pk_org: true, pk_org_v: true, supplier: true, supplier_v: true });
        props.cardTable.setColEditableByKey(tableId, ['supplier', 'supplier_v'], true);
    }
}


/**
 * 单据审批流可编辑字段
 * @param {*} that 
 * @param {*} pk_bill 
 * @param {*} billType 
 * @param {*} appcode 
 */
function billEditProperties(that, pk_bill, billType, appcode) {
    let scene = that.props.getUrlParam('scene');
    ajax({
        url: '/nccloud/arap/arappub/billCanEditProperties.do',
        data: {
            pk_bill: pk_bill,
            billType: billType,
            appcode: appcode
        },
        success: (res) => {
            if (res.success) {
                that.state.buttonfalg = true;
                that.props.resMetaAfterPkorgEdit();
                if (res.data && res.data.head) {
                    that.props.form.setFormItemsDisabled(that.formId, res.data.head);
                    that.headBack = res.data.headBack
                }
                if (res.data && res.data.body) {
                    that.props.cardTable.setColEditableByKey(that.tableId, res.data.body, true)
                    that.bodyBack = res.data.body
                }
                if (that.headBack && !res.data) {
                    that.props.form.setFormItemsDisabled(that.formId, that.headBack);
                    that.props.cardTable.setColEditableByKey(that.tableId, that.bodyBack, false)
                }
                if((scene == 'approve' || scene == 'approvesce'||scene == 'zycl')){
                     if(!res.data.head){
                        that.props.initMetaByPkorg('pk_org_v');
                     }
                     if(!res.data.body){
                        that.props.initMetaByPkorg('pk_org_v');
                     }
                }
                that.props.form.setFormItemsDisabled(that.formId, { pk_org: true, pk_org_v: true });
            }
        }
    });
}
/**
 * 资金推收款付款字段编辑性控制
 * @param {*} that 
 */
function cardFieldsEditableFromCM(that) {
    let cardData = that.props.createMasterChildData(that.getPagecode(), that.formId, that.tableId);
    let top_billtype = '';
    let billtype = '';
    if (cardData && cardData.body && cardData.body[that.tableId] && cardData.body[that.tableId].rows) {
        let bodyrows = cardData.body[that.tableId].rows;
        top_billtype = bodyrows[0].values.top_billtype.value
        billtype = bodyrows[0].values.pk_billtype.value
    }
    let formFields = []
    let tableFieds = []
    if (top_billtype == "36H1" && billtype == "F2") {
        formFields = ['pk_org', 'pk_org_v']
        tableFieds = ['checktype', 'checkno_display']
    }
    if (formFields && formFields.length > 0 && tableFieds && tableFieds.length > 0) {
        var map = {};
        for (let i = 0; i < formFields.length; i++) {
            var key = formFields[i];
            map[key] = true;
        }
        that.props.beforeUpdatePage(); //打开开关
        that.props.form.setFormItemsDisabled(that.formId, map);
        that.props.cardTable.setColEditableByKey(that.tableId, tableFieds, true);
        that.props.updatePage(that.formId, that.tableId); //关闭开关
    }
}

/**
 * 资产单据（推拉） --》F0应收单,F1应付单
 * 字段编辑性控制
 * @param {*} props 
 * @param {*} formId 
 * @param {*} tableId 
 */
function cardFieldsEditable(that) {
    let cardData = that.props.createMasterChildData(that.getPagecode(), that.formId, that.tableId);
    let top_billtype = '';
    let billtype = '';
    if (cardData && cardData.body && cardData.body[that.tableId] && cardData.body[that.tableId].rows) {
        let bodyrows = cardData.body[that.tableId].rows;
        top_billtype = bodyrows[0].values.top_billtype.value
        billtype = bodyrows[0].values.pk_billtype.value
    }
    let meta = that.props.meta.getMeta();
    let arapbilltype = ['F0', 'F1', 'F2', 'F3'];
    let formFields = []
    let tableFieds = []
    if (top_billtype && (top_billtype == "4A2F" || top_billtype == "4BL0" || top_billtype == "4BL3") && billtype == "F0") {
        // 4A2F租出租金结算单（推拉） --》F0应收单
        // 4BL0租出合同维护（推） --》F0应收单
        // 4BL3租出费用维护（推） --》F0应收单
        formFields = ['pk_org', 'pk_fiorg', 'pk_pcorg', 'sett_org', 'pk_org_v', 'pk_fiorg_v', 'pk_pcorg_v', 'sett_org_v', 'outbusitype', 'pk_group', 'creationtime', 'creator',
            'pk_billtype', 'pk_tradetype', 'billclass', 'isinit', 'billdate', 'syscode', 'src_syscode', 'billstatus', 'billmaker', 'pk_busitype', 'pk_psndoc',
            'customer', 'pk_currtype', 'objtype']
        tableFieds = ['pk_org', 'pk_pcorg', 'pk_fiorg', 'sett_org', 'pk_pcorg_v', 'pk_org_v', 'pk_fiorg_v', 'sett_org_v', 'customer',
            'equipmentcode', 'billdate', 'pk_group', 'pk_billtype', 'billclass', 'pk_tradetype', 'busidate', 'objtype',
            'direction', 'pk_currtype', 'pk_psndoc', 'money_de', 'local_money_de', 'money_bal', 'local_money_bal', 'notax_de',
            'local_notax_de', 'price', 'taxprice', 'top_billid', 'top_itemid', 'top_billtype', 'top_tradetype', 'src_tradetype',
            'src_billtype', 'src_billid', 'src_itemid', 'pk_payterm', 'assetpactno', 'groupdebit', 'globaldebit', 'groupbalance', 'globalbalance', 'project']
    } else if (top_billtype && (top_billtype == "4A3F" || top_billtype == "4A3H") && billtype == "F1") {
        // 4A3F租入租金结算单（推拉） --》F1应付单
        // 4A3H临时租入租金结算单（推拉） --》F1应付单
        formFields = ['billclass', 'isinit', 'billdate', 'syscode', 'src_syscode', 'billstatus', 'billmaker', 'pk_busitype',
            'pk_psndoc', 'supplier', 'supplier_v', 'pk_currtype', 'objtype', 'pk_org_v', 'pk_fiorg_v', 'pk_pcorg_v', 'sett_org_v',
            'pk_org', 'pk_pcorg', 'sett_org', 'outbusitype', 'pk_group', 'creationtime', 'creator', 'pk_billtype', 'pk_tradetype']
        tableFieds = ['pk_org', 'pk_fiorg', 'pk_pcorg', 'pk_pcorg_v', 'pk_org_v', 'pk_fiorg_v', 'sett_org_v', 'sett_org',
            'supplier', 'supplier_v', 'equipmentcode', 'billdate', 'pk_group', 'pk_billtype', 'billclass', 'pk_tradetype', 'busidate',
            'objtype', 'direction', 'pk_currtype', 'pk_psndoc', 'local_money_cr', 'money_cr', 'money_bal',
            'local_money_bal', 'price', 'taxprice', 'top_billid', 'top_itemid', 'top_billtype', 'top_tradetype',
            'src_tradetype', 'src_billtype', 'src_billid', 'src_itemid', 'pk_payterm', 'assetpactno', 'contractno',
            'groupcrebit', 'globalcrebit', 'groupbalance', 'globalbalance', 'project']
        if (top_billtype == "4A3F") {
            tableFieds.push('quantity_cr')
        }
    } else if (top_billtype && (top_billtype == "4A18" || top_billtype == "4A23" || top_billtype == "4A24" || top_billtype == "4A49")) {
        //资产处置 4A18 //安装调试 4A24 //资产投保 4A23 //保险索赔 4A49
        formFields = ['pk_currtype', 'rate']
        tableFieds = ['pk_currtype', 'rate', 'money_de', 'local_money_de', 'local_notax_cr', 'notax_de', 'local_notax_de', 'money_cr', 'local_money_cr', 'local_tax_cr', 'notax_cr', 'local_notax_cr']
    } else if (top_billtype && top_billtype == "4A77" && billtype == "F0") {
        //周转材租赁结算-》应收     购销合同？----摘要默认结算应收租金不可编辑
        formFields = ['pk_org', 'pk_pcorg', 'customer', 'scomment', 'pk_currtype', 'billdate', 'billmaker', 'approver', 'pk_org_v']
        tableFieds = ['pk_currtype', 'money_de', 'local_money_de', 'groupdebit', 'globaldebit', 'contractno', 'assetpactno', 'scomment']
    } else if (top_billtype && top_billtype == "4BL9" && billtype == "F0") {
        //租金结算-》应收     
        formFields = ['pk_org_v', 'pk_org', 'pk_pcorg', 'customer', 'scomment', 'pk_currtype', 'billdate', 'billmaker', 'approver']
        tableFieds = ['pk_org_v', 'pk_org', 'sett_org', 'pk_pcorg', 'pk_currtype', 'money_bal', 'customer', 'equipmentcode', 'billdate',
            'money_de', 'local_money_de', 'groupdebit', 'globaldebit', 'contractno', 'price ', 'assetpactno', 'scomment',
            'taxprice', 'objtype', 'pk_payterm', 'project', 'busidate']
    } else if (top_billtype && (top_billtype == "4A3L" && billtype == "F1")) {
        // 资产租入付款申请-》应付   
        formFields = ['pk_org_v', 'pk_org', 'billdate', 'objtype']
        tableFieds = ['pk_org_v', 'pk_org', 'sett_org', 'sett_org_v', 'ratedate', 'rate', 'objtype', 'supplier', 'supplier_v', 'pk_currtype',
            'money_cr', 'local_money_cr', 'groupcrebit', 'globalcrebit']
    } else if (top_billtype && (top_billtype == "4BLA" && billtype == "F0")) {
        // 资产租出收款申请-》应收
        formFields = ['pk_org_v', 'pk_org', 'billdate', 'objtype']
        tableFieds = ['pk_org_v', 'pk_org', 'sett_org', 'sett_org_v', 'ratedate', 'rate', 'objtype', 'customer', 'customer_v', 'pk_currtype',
            'money_de', 'local_money_de', 'groupdebit', 'globaldebit']

    } else if (top_billtype && (arapbilltype.indexOf(billtype) != -1)) {
        //收付内部拉单不允许修改settlemoney,settlecurr
        let settle = ['settlemoney', 'settlecurr']
        that.props.cardTable.setColEditableByKey(that.tableId, settle, true);
    }
    if (formFields && formFields.length > 0 && tableFieds && tableFieds.length > 0) {
        var map = {};
        for (let i = 0; i < formFields.length; i++) {
            var key = formFields[i];
            map[key] = true;
        }
        that.props.beforeUpdatePage(); //打开开关
        that.props.form.setFormItemsDisabled(that.formId, map);
        that.props.cardTable.setColEditableByKey(that.tableId, tableFieds, true);
        that.props.updatePage(that.formId, that.tableId); //关闭开关
    }
}
function cardFieldsEditableWithVersion(that, formFields, tableFieds) {
    formFields.push('pk_deptid', 'pk_pcorg','isfromindependent');//是否独立 结算信息不可编辑
    tableFieds.push('pk_pcorg', 'pk_deptid','pausetransact');
    let tableValues = that.props.cardTable.getAllRows(that.tableId);
    let hasTop  = null;
    if (tableValues && tableValues[0] && tableValues[0].values) {
        hasTop = tableValues[0].values.top_billtype.value;
    }
    if(hasTop){
        formFields.push('invoiceno');
        tableFieds.push('invoiceno');
    }
   if (formFields && formFields.length > 0 && tableFieds && tableFieds.length > 0) {
        var map = {};
        for (let i = 0; i < formFields.length; i++) {
            var key = formFields[i];
            map[key] = true;
        }      
        that.props.form.setFormItemsDisabled(that.formId, map);
        that.props.cardTable.setColEditableByKey(that.tableId, tableFieds, true);
    }
}
function cardFieldsEditableWithProxy(that) {
    let formFields = [];
    let tableFieds = [];
    //1.结算状态不能编辑
    formFields.push('settleflag', 'redbacktype','isreded');
    //2部门 利润中心  最新版本不可编辑
    cardFieldsEditableWithVersion(that, formFields, tableFieds);
    let pagestatus = that.props.getUrlParam('status')
    if (pagestatus != 'browse') {
        //3.止付红冲/退票红冲/退票红冲取消核心，仅仅允许编辑税额 无税金额 表体  表头的摘要
        addStopPayField(that, formFields, tableFieds);
        //4到账通知 退款生成的单据 金额不可调整。
        noticeOfReceiptField(that, formFields, tableFieds);

        //外系统生成单据控制
        otherSysGenBillCtrl(that);
    }

}
/**
 * 编辑性释放
 * @param {} that 
 */
function cardFieldsEditableWithResetProxy(that) {
    let formFields = [];
    let tableFieds = [];
    //1.结算状态不能编辑
    formFields.push('settleflag', 'redbacktype', 'isreded');
    //2部门 利润中心  最新版本不可编辑
    cardFieldsEditableWithVersion(that, formFields, tableFieds);
    let cashMeta = metaCache.getMetaCache(that.appcode, that.pagecode);
    if(!cashMeta){
        return;
    }
    let items = cashMeta.template?cashMeta.template.bodys.items:null;
    let headitems = cashMeta.template?cashMeta.template.head.items:null;
    let editTable = [];
    let diseditTable = [];
    let editmap = {};
    let diseditmap = {};
    if(headitems){
        for (let i = 0; i < headitems.length; i++) {
            var key = headitems[i].attrcode;
            if (headitems[i].disabled) {
                diseditmap[key] = true;
            } else {
                editmap[key] = false;
            }
        }
    }
   if(items){
    for (let j = 0; j < items.length; j++) {
        var attrcode = items[j].attrcode;
        if (items[j].disabled) {
            diseditTable.push(attrcode);
        } else {
            editTable.push(attrcode);
        }
    }
   }
    that.props.form.setFormItemsDisabled(that.formId, editmap);
    that.props.cardTable.setColEditableByKey(that.tableId, diseditTable, true);
    that.props.cardTable.setColEditableByKey(that.tableId, editTable, false);

}
function addStopPayField(that, formFields, tableFieds) {
    let redbacktype = that.props.form.getFormItemsValue(that.formId, 'redbacktype');
    if (!redbacktype || (redbacktype && (redbacktype.value != 1 && redbacktype.value != 2  && redbacktype.value != 3&&redbacktype.value != 5|| redbacktype.value == null))) {
        return;
    }
    let formValues = that.props.form.getAllFormValue(that.formId);
    if (formValues && formValues.rows[0] && formValues.rows.values) {
        let fieldArray = Object.keys(formValues.rows[0].values);
        for (let i = 0; i < fieldArray.length; i++) {
            formFields.push(fieldArray[i]);
        }
    }

    let tableValues = that.props.cardTable.getAllRows(that.tableId);
    if (tableValues && tableValues[0].values) {
        let fieldtableArray = Object.keys(tableValues[0].values);
        for (let i = 0; i < fieldtableArray.length; i++) {
            tableFieds.push(fieldtableArray[i]);
        }
    }
    if (formFields && formFields.length > 0 && tableFieds && tableFieds.length > 0) {
        var map = {};
        for (let i = 0; i < formFields.length; i++) {
            var key = formFields[i];
            map[key] = true;
        }        
        that.props.form.setFormItemsDisabled(that.formId, map);
        that.props.cardTable.setColEditableByKey(that.tableId, tableFieds, true);
    }
    let canEditFieldForm = ['scomment']
    let canEditFieldTable = ['scomment','local_tax_de','local_tax_cr']


    var map = {};
    for (let i = 0; i < canEditFieldForm.length; i++) {
        var key = canEditFieldForm[i];
        map[key] = false;
    }
    that.props.beforeUpdatePage(); //打开开关
    that.props.form.setFormItemsDisabled(that.formId, map);
    that.props.cardTable.setColEditableByKey(that.tableId, canEditFieldTable, false);
    that.props.updatePage(that.formId, that.tableId); //关闭开关
}

function noticeOfReceiptField(that, formFields, tableFieds) {
    let redbacktype = that.props.form.getFormItemsValue(that.formId, 'redbacktype');
    let tableValues = that.props.cardTable.getAllRows(that.tableId);
    let top_billtype = null;
    if (tableValues && tableValues[0] && tableValues[0].values) {
        top_billtype = tableValues[0].values.top_billtype.value;
    }
    if (!redbacktype&&!redbacktype.value || ((redbacktype && redbacktype.value != 4) ||top_billtype != '36S3') || (!(redbacktype == "" || redbacktype == null) && top_billtype == '36S3')) {
        return;
    }
    formFields = ['pk_org', 'pk_org_v', 'objtype', 'supplier_v', 'customer_v', 'pk_currtype', 'rate', 'payaccount', 'recaccount', 'money', 'local_money', 'grouplocal', 'grouprate', 'globallocal', 'globalrate', 'commpaybegindate', 'commpaybegindate', 'commpayenddate', 'isforce']
    tableFieds = ['objtype', 'supplier_v', 'customer_v', 'pk_currtype', 'rate', 'grouprate', 'globalrate', 'payaccount', 'recaccount', 'commpayer', 'commpaystatus', 'commpaytype', 'money_de', 'local_money_de', 'quantity_de', 'money_bal', 'local_money_bal', 'quantity_bal', 'local_tax_de',
        'notax_de', 'local_notax_de', 'groupdebit', 'grouptax_de', 'groupnotax_de', 'globaldebit', 'globaltax_de', 'globalnotax_de', 'quantity_cr', 'local_money_cr', 'money_cr',
        'local_tax_cr', 'notax_cr', 'local_notax_cr', 'groupcrebit', 'grouptax_cre', 'groupnotax_cre',
        'globalcrebit', 'globaltax_cre', 'globalnotax_cre', 'occupationmny', 'price', 'groupbalance', 'globalbalance', 'taxprice', 'caltaxmny', 'nosubtax','checktype', 'checkno_display']
    if (formFields && formFields.length > 0 && tableFieds && tableFieds.length > 0) {
        var map = {};
        for (let i = 0; i < formFields.length; i++) {
            var key = formFields[i];
            map[key] = true;
        }
        that.props.form.setFormItemsDisabled(that.formId, map);
        that.props.cardTable.setColEditableByKey(that.tableId, tableFieds, true);
    }
}

function otherSysGenBillCtrl(that){
    let tableValues = that.props.cardTable.getAllRows(that.tableId);
    let top_billtype = null;
    if (tableValues && tableValues[0] && tableValues[0].values) {
        top_billtype = tableValues[0].values.top_billtype.value;
    }
    if(!top_billtype){
        return;
    }
    var formFields = [];
    var tableFieds = [];
    if('Z3' == top_billtype||"21" == top_billtype){//销售合同生成单据不允许修改币种
        formFields.push('pk_currtype');
       
        tableFieds.push('pk_currtype');
    }
    var map = {};
    if(formFields&&formFields.length>0){
        for (let i = 0; i < formFields.length; i++) {
            var key = formFields[i];
            map[key] = true;
        }
    } 
    that.props.form.setFormItemsDisabled(that.formId, map);
    that.props.cardTable.setColEditableByKey(that.tableId, tableFieds, true);
}

/**
 * 已生成有效开票申请单的应收单修改时，字段编辑性控制
 * @param {*} props 
 * @param {*} formId 
 * @param {*} tableId
 * @param {*} flag 
 */
function dealHasInvoiceRecBillField(props, formId, tableId, flag) {
    props.form.setFormItemsDisabled(formId, 
        { 
            'objtype': flag,   // 往来对象
            'customer': flag,  // 客户
            'pk_currtype': flag,  //币种
            'customer_v': flag // 客户版本
        }
    );
    props.cardTable.setColEditableByKey(
        tableId,
        [
            'material', // 物料
            'price',    // 单价
            'taxprice', //含税单价
            'local_taxprice', //本币含税单价
            'quantity_de', // 借方数量
            'money_de',  // 借方原币金额
            'local_money_de',  // 借方本币金额
            'notax_de', // 借方原币无税金额
            'local_notax_de', // 借方本币无税金额
            'local_tax_de', // 税额
            'taxrate', // 税率
            'taxcodeid', //税码
            'customer_v', // 客户版本
            'customer', // 客户
            'pk_currtype',  //币种
            'objtype' // 往来对象
        ],
        flag
    );
}
/**
 * 检查是否需要释放编辑性
 * @param {*} that 
 */
function checkRedType(that){
	let red = that.props.form.getFormItemsValue(that.formId, 'redbacktype');
	let tableValues = that.props.cardTable.getAllRows(that.tableId);
	let top_billtype = null;
	if (tableValues && tableValues[0] && tableValues[0].values) {
		top_billtype = tableValues[0].values.top_billtype.value;
	}
	if (!(!red || (red && (red.value != 1 && red.value != 2 && red.value != 3 && red.value != 5&&(top_billtype != '36S3'&&red.value != 4)) || red.value == null))){
		return true;
	}else{
		return false;
	}
}

export {
    objtypeEditable, dealCommisionPayField, F0ToF3FieldsEditable,
    applyToF3FieldsEditable, fctToArapFieldEditable, billEditProperties, cardFieldsEditableFromCM,
    cardFieldsEditable, puToArapFieldEditable, cardFieldsEditableWithProxy, dealHasInvoiceRecBillField,dealCommisionPayFieldBack,cardFieldsEditableWithResetProxy,checkRedType
}
/*i0/DZTnkyLJbxtpRv5YHeEjlgIAayf7nNKe50skxlHJRBFugw4+AF+leK+r2aMupmfI9AklmWTqf
JWM/nPz4ag==*/